<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <title>layui</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="../../../../static/lib/layuiadmin/layui/css/layui.css" media="all">
</head>
<body>

<table class="layui-hide" id="test" lay-filter="test"></table>

<script type="text/html" id="toolbarDemo">
    <div class="layui-btn-container">
        <button class="layui-btn layui-btn-sm" lay-event="getCheckData">确定</button>
        <span style=" margin-left: 110px; font-size: 16px">请手动选择下一活动！</span>
    </div>
</script>

<script src="../../../../static/lib/layuiadmin/layui/layui.js"></script>
<script type="text/javascript" src="../../../common/common.js"></script>
<script type="text/javascript" src="../../../common/jquery-3.3.1.min.js"></script>
<!-- 注意：如果你直接复制所有代码到本地，上述js路径需要改成你本地的 -->

<script>
    var wfId = RequestURLParam.getParam("wfId");
    var activityId = RequestURLParam.getParam("activityId");
    var id = RequestURLParam.getParam("taskId");
    layui.use('table', function () {
        var table = layui.table;
        table.render({
            elem: '#test'
            , url: '/wf/activity/wfnull'
            , method: 'post'
            , where: {'id':id, 'wfId':wfId, 'wfaId':activityId}
            , toolbar: '#toolbarDemo'
            , title: '用户数据表'
            , limit: 5
            , height: 400
            , limits: [5, 10, 20]
            , defaultToolbar: false    //右侧工具
            , response: {
                statusName: 'OK'
                , statusCode: 'OK'
                , countName: 'total'
                , dataName: 'List'
            }
            , cols: [[
                {type: 'radio', fixed: 'left', width: '7%'}
                , {field: 'activityName', title: '活动名', width: '93%'}
            ]]
            , page: true
        });
        //头工具栏事件
        table.on('toolbar(test)', function (obj) {
            var checkStatus = table.checkStatus(obj.config.id); //获取选中行状态
            switch (obj.event) {
                case 'getCheckData':
                    var data = checkStatus.data[0]  //获取选中行数据
                        , activityId = data.wfaId
                        , url = "/wf/systask/key/savewfnull"
                    $.ajax({
                        url: url,
                        data:{
                            activityId:activityId,
                            id:id || 0
                        },
                        type: 'post',
                        traditional: true,
                        success: function (data) {
                            if (data.OK == "OK") {
                                var userName = "";
                                if (data.operatorList != '' && data.operatorList != undefined) {
                                    for (var i = 0; i < data.operatorList.length; i++) {
                                        userName = userName + data.operatorList[i].userName + " ";
                                    }
                                    ;
                                    layer.alert('流程跳转成功！申请已发送至【' + data.wfActivity.activityName + '】环节，并对用户【' + userName + '】发起了待办', {
                                            icon: 1
                                        }, function (i) {
                                            layer.close(i)
                                            if (parent.$("#layerNull").length > 0) {
                                                parent.parent.layer.close(parent.$("#layerNull").val())
                                                parent.parent.location.reload()
                                            }
                                        }
                                    )
                                } else {
                                    if (data.wfActivity != null && data.wfActivity.activityCode != undefined && data.wfActivity.activityCode == "end") {
                                        layer.alert('流程跳转成功，流程已结束！', {
                                                icon: 1
                                            }, function (i) {
                                                layer.close(i)
                                                location.reload()
                                            if (parent.$("#layerNull").length > 0) {
                                                parent.parent.layer.close(parent.$("#layerNull").val())
                                                parent.parent.location.reload()
                                            }
                                            }
                                        )
                                    } else {
                                        if (data.user == "null") {
                                            layer.msg('提交失败！下一活动办理人找不到！', {
                                                icon: 2,
                                                time: 2000 //2秒关闭（如果不配置，默认是3秒）
                                            }, function () {
                                            })
                                        } else {
                                            layer.alert('流程跳转异常！请联系管理员！', {
                                                    icon: 1
                                                }, function (i) {
                                                    layer.close(i)
                                                    location.reload()
                                                if (parent.$("#layerNull").length > 0) {
                                                    parent.parent.layer.close(parent.$("#layerNull").val())
                                                    parent.parent.location.reload()
                                                }
                                                }
                                            )
                                        }
                                    }
                                }
                            }
                            else if (data.wfState == "over") {
                                layer.alert('请不要重复提交代办！', {
                                        icon: 1
                                    }, function (i) {
                                        layer.close(i)
                                        location.reload()
                                    if (parent.$("#layerNull").length > 0) {
                                        parent.parent.layer.close(parent.$("#layerNull").val())
                                        parent.parent.location.reload()
                                    }
                                    }
                                )
                            }
                            else {
                                layer.msg('流程操作失败！', {
                                    icon: 1,
                                    time: 2000 //2秒关闭（如果不配置，默认是3秒）
                                }, function () {
                                })
                            }
                        },
                        error: function () {
                            layer.msg('流程操作失败！', {
                                icon: 1,
                                time: 2000 //2秒关闭（如果不配置，默认是3秒）
                            }, function () {
                            })
                        }
                    });
                    break;
            }
        });
    });
</script>

</body>
</html>